After the user is authenticated, OPC Wizard determines whether the user is authorized to log on to the server (in OPC UA terms, activate the session).
If the logon access is granted, the OPC Wizard then determines the security roles the user has. The security roles can be provided by the user manager objects, where you can simply configure the security roles for each user declaratively. Alternatively, you can write a custom code to take over the determination of user security roles, and implement whatever logic is necessary in your scenario.
OPC Wizard also takes care of automatically assigning certain implicit security roles according to the OPC UA rules.
If the client uses a username and password user identity token and the user is successfully authenticated, OPC Wizard checks whether the user is enabled, and will not allows disabled users to logon to the server, even if they are authenticated. You can control whether the user is enabled when the user is created using the Create Method, or later using the SetEnabled Method on the name and password user manager.
When an anonymous user identity is allowed and an anonymous user token is used, the logon is automatically granted.
A user that accesses the server is associated with a set of security roles. The security roles are then used to determine the permissions the user has. OPC UA specifications define certain well-known security roles, and you can also add your own. Security role in OPC UA is identified by its role Id, which is an OPC UA node Id of the node that represents the security role. In OPC Wizard, the security role is represented by an instance of UASecurityRole Class, which also contains additional data, such as the role name.
The standard well-known OPC UA security roles are defined in the UASecurityRoles Class. Following well-known roles are in this class:
| Name | Description |
|---|---|
| Anonymous | The OPC UA Anonymous well-known security role. |
| AuthenticatedUser | The OPC UA AuthenticatedUser well-known security role. |
| ConfigureAdmin | The OPC UA ConfigureAdmin well-known security role. |
| Engineer | The OPC UA Engineer well-known security role. |
| Observer | The OPC UA Observer well-known security role. |
| Operator | The OPC UA Operator well-known security role. |
| SecurityAdmin | The OPC UA SecurityAdmin well-known security role. |
| SecurityKeyServerAccess | The OPC UA SecurityKeyServerAccess well-known security role. |
| SecurityKeyServerAdmin | The OPC UA SecurityKeyServerAdmin well-known security role. |
| SecurityKeyServerPush | The OPC UA SecurityKeyServerPush well-known security role. |
| Supervisor | The OPC UA Supervisor well-known security role. |
| TrustedApplication | The OPC UA TrustedApplication well-known security role. |
For a discussion of well-known OPC UA security roles and their usage, see OPC UA Well-Known Security Roles.
You can create your own OPC UA security role using the Create Method, as illustrated in th example below.
In addition to explicitly defined roles for a user, OPC Wizard always adds certain implicit security roles to the security principal. The rules that govern the implicit security roles are laid out in OPC UA specifications. Briefly:
In its default behavior, OPC Wizard obtains the security roles, i.e. authorizes the user, using the same user manager objects that were used for authentication.
If the client has used an anonymous user identity token, the IDs of the security roles are taken from the SecurityRoleIdSet Property of the anonymous user manager. By default, this set is empty, and anonymous users thus only get the implicit security roles as described above. You can modify this set if you want to assign additional roles to anonymous users.
If the client has used a username and password security token, the IDs of their security roles are obtained from the name and password user manager object (ReadOnlyNameAndPassword Property) using the GetSecurityRoleIdList Method. If you want to configure the security roles IDs associated with a specific user, access the NameAndPassword Property of UserManagers, and use the AddSecurityRoleId and RemoveSecurityRoleId methods.
You can also assign the security roles to the user right when creating the user, with the CreateWithSecurityRoleIds Extension Method.
The following example shows how to create a user with username and password, and assign it specific OPC UA roles.
If you have special needs, you can replace the user assignment mechanism described above by your own.
Similarly to what has been described in OPC Wizard User Authentication, you can do so by creating and using your own user manager objects.
Alternatively, you can also handle the GetIdentityContextSecurityRoleIds Event. In the event arguments, your code receives an UAIdentityContext that contains the information needed for authorization decisions. Your code will determine the security role IDs associated with the given identity context, and then call the HandleAndReturn Method to return them and indicate that the default processing should not be used.